package com.yy.wga.goods.service.api.response;

import com.alibaba.fastjson.JSONObject;
import com.yy.wga.common.core.exception.BusinessException;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

@Slf4j
public class ApiResult {


    public static <T extends BaseApiDTO> T handle(JSONObject jsonObject, Class<T> clazz) {
        T t = jsonObject.toJavaObject(clazz);
        if (Objects.isNull(t)) {
            throw new BusinessException("Api调用失败");
        }
        if (!t.isSuccsss()) {
//            WxErrorService wxErrorApi = SpringUtils.getBean(WxErrorService.class);
//            JSONObject wxError = wxErrorApi.getWxError(t.getRid());
//            System.out.println(JsonUtils.toJSON(wxError));
            String errrorMsg = "Api调用失败,错误信息:" + t.getErrmsg();
            throw new BusinessException(String.valueOf(t.getErrcode()), errrorMsg);
        }
        return t;
    }
}
